﻿<%@ WebHandler Language="VB" Class="UploadDocumentFile" %>

Imports System
Imports System.Web
Imports System.Data
Imports VSModel
Imports Newtonsoft.Json
Imports System.Xml
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports Cls_Common

Public Class UploadDocumentFile : Implements IHttpHandler
	
	Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
		Dim fileCol As HttpFileCollection = context.Request.Files
		Dim arr As String = ""
		For i As Integer = 0 To fileCol.Count - 1
			Dim file As HttpPostedFile = fileCol(i)
			Dim strFileNamePath As String
			Dim _timeFile As String = DateTime.Now.ToFileTime().ToString() & "___"
			'Logic to find the FileName (excluding the path)
			strFileNamePath = _timeFile & file.FileName
			Dim relativePath As String = context.Server.MapPath("~/Uploads/MSDS/")
			If Not directory.Exists(relativePath) Then
				directory.CreateDirectory(relativePath)
			End If
			If (System.IO.File.Exists(relativePath + strFileNamePath)) Then
				System.IO.File.Delete(relativePath + strFileNamePath)
			End If
			context.Request.Files("fileAttach").SaveAs(relativePath & strFileNamePath)
			arr = MainDomain & _timeFile & file.FileName & "##" & (relativePath & strFileNamePath).Replace("\","@").Replace("/","@")
		Next
		context.Response.Write(arr)
	End Sub
	
	Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
		Get
			Return False
		End Get
	End Property

End Class